You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.3 KiB
36 lines
1.3 KiB
import { dbGlobal } from "drizzle-pkg/lib/db";
|
|
import { users } from "drizzle-pkg/lib/schema/auth";
|
|
import { and, eq } from "drizzle-orm";
|
|
import { getGlobalConfigValue, getMergedConfigValue } from "#server/service/config";
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const publicSlug = event.context.params?.publicSlug;
|
|
if (!publicSlug || typeof publicSlug !== "string") {
|
|
throw createError({ statusCode: 400, statusMessage: "无效主页" });
|
|
}
|
|
|
|
const [owner] = await dbGlobal
|
|
.select()
|
|
.from(users)
|
|
.where(and(eq(users.publicSlug, publicSlug), eq(users.status, "active")))
|
|
.limit(1);
|
|
|
|
if (!owner) {
|
|
throw createError({ statusCode: 404, statusMessage: "未找到" });
|
|
}
|
|
|
|
const [titleCfg, iconCfg, siteName] = await Promise.all([
|
|
getMergedConfigValue(owner.id, "publicHomeHeaderTitle"),
|
|
getMergedConfigValue(owner.id, "publicHomeHeaderIconUrl"),
|
|
getGlobalConfigValue("siteName"),
|
|
]);
|
|
|
|
const configuredTitle = typeof titleCfg === "string" ? titleCfg.trim() : "";
|
|
const configuredIcon = typeof iconCfg === "string" ? iconCfg.trim() : "";
|
|
const site = typeof siteName === "string" ? siteName.trim() : "";
|
|
|
|
const title = configuredTitle || site;
|
|
const iconUrl = configuredIcon.length > 0 ? configuredIcon : null;
|
|
|
|
return R.success({ title, iconUrl });
|
|
});
|
|
|